/*
 *
 *  Copyright (C) 2007-2020 SimplyCore, LLC
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 *
 */

#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/ioctl.h>
#include <linux/usb.h>
#include <linux/types.h>
#include <linux/fs.h>
#include <linux/cdev.h>
#include <linux/poll.h>
#include <linux/spinlock.h>
#include <linux/list.h>
#include <linux/version.h>
#include <linux/kref.h>
#include <linux/device.h>
#include <linux/compat.h>
#include <linux/mm.h>
#include <linux/vmalloc.h>
#include <linux/module.h>
#include <asm/uaccess.h>
#define KERNEL_GT(IllllIl,IIIIIII,llllIlII)			(LINUX_VERSION_CODE > \
KERNEL_VERSION((IllllIl),(IIIIIII),(llllIlII)))
#define KERNEL_LT(IllllIl,IIIIIII,llllIlII)			(LINUX_VERSION_CODE < \
KERNEL_VERSION((IllllIl),(IIIIIII),(llllIlII)))
#define KERNEL_EQ(IllllIl,IIIIIII,llllIlII)			(LINUX_VERSION_CODE == \
KERNEL_VERSION((IllllIl),(IIIIIII),(llllIlII)))
#define KERNEL_GT_EQ(IllllIl,IIIIIII,llllIlII)			(LINUX_VERSION_CODE >= \
KERNEL_VERSION((IllllIl),(IIIIIII),(llllIlII)))
#define KERNEL_LT_EQ(IllllIl,IIIIIII,llllIlII)			(LINUX_VERSION_CODE <= \
KERNEL_VERSION((IllllIl),(IIIIIII),(llllIlII)))
#if defined(RHEL_RELEASE_CODE) 
#define RHEL_RELEASE_GT(IllllIl,IIIIIII) 		(RHEL_RELEASE_CODE > \
RHEL_RELEASE_VERSION((IllllIl),(IIIIIII)))
#define RHEL_RELEASE_LT(IllllIl,IIIIIII)		(RHEL_RELEASE_CODE < \
RHEL_RELEASE_VERSION((IllllIl),(IIIIIII)))
#define RHEL_RELEASE_EQ(IllllIl,IIIIIII)		(RHEL_RELEASE_CODE == \
RHEL_RELEASE_VERSION((IllllIl),(IIIIIII)))
#define RHEL_RELEASE_GT_EQ(IllllIl,IIIIIII)		(RHEL_RELEASE_CODE >= \
RHEL_RELEASE_VERSION((IllllIl),(IIIIIII)))
#define RHEL_RELEASE_LT_EQ(IllllIl,IIIIIII)		(RHEL_RELEASE_CODE <= \
RHEL_RELEASE_VERSION((IllllIl),(IIIIIII)))
#else
#define RHEL_RELEASE_GT(IllllIl,IIIIIII) 		(0x124c+2301-0x1b49)
#define RHEL_RELEASE_LT(IllllIl,IIIIIII)		(0xc84+5834-0x234e)
#define RHEL_RELEASE_EQ(IllllIl,IIIIIII)		(0xe23+6213-0x2668)
#define RHEL_RELEASE_GT_EQ(IllllIl,IIIIIII)		(0x171+7341-0x1e1e)
#define RHEL_RELEASE_LT_EQ(IllllIl,IIIIIII)		(0x3b7+5275-0x1852)
#endif

#ifndef BUS_ID_SIZE
#define BUS_ID_SIZE (0xae3+3497-0x1878)
#endif
#include "../public/pubstt2.h"
#include "../public/apitypes.h"
#include "../public/pubuniprotocol.h"
#include "../public/interface.h"
#include "../public/public_devices.h"
#include "utils.h"
#include "driver.h"
#include "cdev.h"
#include "stub.h"
#include "vhci.h"
#include "minor_loader.h"
#include "minor_stub.h"
#include "minor_vbus.h"
#include "minor_vstub.h"
#include "urb_chain.h"
#include "sg.h"

#if KERNEL_LT_EQ((0x168a+1397-0x1bfd),(0xbbd+3747-0x1a5a),(0xaef+1961-0x1289))
#define IIIlllIlI __stringify(KBUILD_MODNAME)
#else
#define IIIlllIlI KBUILD_MODNAME
#endif

#ifndef CONFIG_PRINTK_TIME
#define IIIIllIl(lllllII, IIIIlII...) printk(KERN_DEBUG \
"\x5b\x25\x30\x39\x75\x5d\x20\x25\x73\x3a\x20" lllllII, jiffies_to_msecs(jiffies\
), IIIlllIlI, ## IIIIlII)
#else
#define IIIIllIl(lllllII, IIIIlII...) printk(KERN_DEBUG "\x25\x73\x3a\x20" \
lllllII, IIIlllIlI, ## IIIIlII)
#endif

#ifdef _USBD_DEBUG_
#define IlllI(lllllII, IIIIlII...) IIIIllIl(lllllII, ##IIIIlII)
#define lIIIl(lllllII, IIIIlII...) IIIIllIl("\x25\x73\x3a\x20" lllllII, __func__\
, ##IIIIlII)
#else
#define IlllI(lllllII, IIIIlII...) do {} while((0x1eea+512-0x20ea))
#define lIIIl(lllllII, IIIIlII...) do {} while((0xe8+5481-0x1651))
#endif

#define IIllIl(lllllII, IIIIlII...) IIIIllIl(lllllII, ##IIIIlII)
extern size_t lllIIlI;
#if KERNEL_LT_EQ((0xb1c+4018-0x1acc),(0x1016+1094-0x1456),(0x140f+212-0x14cc))
typedef unsigned long uintptr_t;
#endif
#if KERNEL_LT_EQ((0x3c6+1517-0x9b1),(0x16d6+1532-0x1ccc),(0xfd4+2869-0x1afa))
#define atomic_xchg(IIIIlIIll, new) (xchg(&((IIIIlIIll)->counter), new))
#endif
#if KERNEL_LT((0xa9d+3368-0x17c2),(0x12a+2652-0xb74),(0x2df+8875-0x258a))




#undef strncasecmp
#define strncasecmp strnicmp
#endif

